package com.controller;


import com.github.pagehelper.PageInfo;
import com.pojo.Site;
import com.service.SiteService;
import com.vo.Result;
import com.vo.SiteVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/Site")
public class SiteController {
    @Resource
    private SiteService siteService;

    @RequestMapping("/SiteXJ/index")
    public String toSite(){
        return "/Site/SiteXJ";
    }

    @RequestMapping("/site/show")
    @ResponseBody
    public Result selectSite(@RequestBody SiteVo siteVo){
        PageInfo<Site> sitePageInfo = siteService.selectAllSite(siteVo);
        return Result.success(sitePageInfo);
    }


    @RequestMapping("/site/show2")
    @ResponseBody
    public Result selectSite2(){
        List<Site> sites = siteService.selectAllSite2();
        return Result.success(sites);
    }


    @RequestMapping("/site/update")
    @ResponseBody
    public Result update(Site site){
        try {
            siteService.updateByPrimaryKey(site);
            return Result.success("修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("修改失败");
        }
    }
    @RequestMapping("/site/add")
    @ResponseBody
    public Result add(Site site){
        try {
            siteService.addSite(site);
            return Result.success("添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("添加失败");
        }
    }

    @RequestMapping("/site/delete")
    @ResponseBody
    public Result delete(Integer id){
        try {
                siteService.deletebyid(id);
                return Result.success("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail("删除失败");
        }
    }


}
